package demo2;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-03-16
 * Time: 14:38
 */

/*
合并两个数组
 */



public class Test {
    public static void Func1(int[] A, int m, int[] B, int n) {
        int i = m - 1;
        int j = n - 1;
        int k = (m + n) - 1;
        while (i >= 0 && j >= 0) {
            if (A[i] > B[j]) {
                A[k] = A[i];
                k--;
                i--;
            } else {
                A[k] = B[j];
                k--;
                j--;
            }
        }
        while (i >= 0) {
            A[k] = A[i];
            k--;
            i--;
        }
        while (j >= 0) {
            A[k] = B[j];
            k--;
            j--;
        }

    }

    public static void main(String[] args) {
        int[] A = {1, 2, 3, 0, 0, 0};
        int[] B = {4, 5, 6};
        Func1(A, 3, B, 3);
        System.out.println(Arrays.toString(A));
    }

}
